package instrarbre;

import java.util.HashMap;
import java.util.LinkedList;
import javax.swing.JTextArea;

public class ASACase extends ASAInstr {

    private int caseValue;
    private LinkedList<ASAInstr> instructions;

    public ASACase() {
        this.instructions = new LinkedList<ASAInstr>();
    }

    public ASACase(int caseValue) {
        this();
        this.caseValue = caseValue;
    }

    public void add(ASAInstr instruction) {
        this.instructions.add(instruction);
    }

    public boolean isCorresponding(int value) {
        return caseValue == value;
    }

    public int getCaseValue() {
        return caseValue;
    }

    @Override
    public void interpreter(HashMap<String, Integer> affectation) {
        for (ASAInstr instruction : instructions) {
            try {
                instruction.interpreter(affectation);
            }
            catch (BreakException e) {
                throw new BreakException();
            }
        }
    }

    @Override
    protected String notationExplorateur(String prefixe) {
        String res = prefixe + getLabelExplorateur() + "\n";
        String prefixeSuiv = prefixe + "  ";
        for (ASAInstr instruction : instructions) {
            res += instruction.notationExplorateur(prefixeSuiv);
        }
        return res;
    }

    @Override
    public void setView(JTextArea area) {
        for (ASAInstr instruction : instructions) {
            instruction.setView(area);
        }
    }
}